<!DOCTYPE html>

<html lang="zh-CN">
	<head>
		<meta charset="utf-8" />
		<meta name="renderer" content="webkit" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<title>文章列表</title>
		<script src="/static/js/jquery-1.9.1.min.js"></script>
        <script src="/static/bootstrap.modal/bootstrap.js"></script>
        <script src="/static/js/base.js"></script>
        <script src="/static/js/avalon.js"></script>
        <script src="/static/js/eqx.js"></script>
        <script src="/static/js/goods/jquery.colorbox-min.js"></script>
        <script src="/static/js/goods/zzsc.js"></script>
		
		
        <link media="all" href="/static/bootstrap.modal/bootstrap.min.css" rel="stylesheet">
        <link media="all" href="/static/css/main.css" rel="stylesheet">
        <link media="all" href="/static/css/base.hy.css" rel="stylesheet">
        <link media="all" href="/static/css/goods.css" rel="stylesheet">
		
		<style type="text/css">
			  .list-content img{margin-right: 8px}
	.check{cursor:pointer}
	table{width: :100%;}
		</style>

		
	</head>
<body>

<div class="box" ms-controller="table">
    <div class="admin-top">
        <div class="admin-title">文章列表 <a href="/user_list.html" class="search-keyword ml5">会员列表</a></div>
		<div class="search-content">

    <div class="list-content">
    	<table class='table table-condensed'>
			<tr class='list_nav'>
			    <td class='tab-width'>id</td>
          <td>文章标题</td>
			    <td>文章内容</td>
			    <td>创建时间</td>
			    <td>操作</td>
			</tr>
      {{range $key, $val := .article}}
			<tr>
        <td>{{$val.Id}}</td>
        <td>{{$val.Title}}</td>
        <td>{{$val.Content}}</td>
        <td>{{$val.Created}}</td>
        <td>
          <a href="javascript:;" class="search-keyword" ms-click="getArticleId({{$val.Id}})">详情</a>
          <a href="javascript:;" class="search-keyword" ms-click="delArticle({{$val.Id}})">删除</a>
        </td>
      </tr>
      {{end}}
		</table>

    <div>
        <form>
          <input type="text" ms-duplex="content.title">
          <input type="text" ms-duplex="content.content">
          <a href="javascript:;" class="search-keyword" ms-click="addArticle()">新增</a>
          <a href="javascript:;" class="search-keyword" ms-click="setArticle()">修改</a>
        </form>
      </div>
    </div>
</div>
<script type="text/javascript"> 
	var vm = avalon.define({
		$id : "table",
    content:{title:"",content:"",id:0},
		//根据ID获取单个文章
		getArticleId: function(id){
			$.post('/article/byId',{id:id}, function(json) {
        vm.content.title = json.Title;
        vm.content.content = json.Content;
        vm.content.id = json.Id;
		  },'json');
		},
	  //新增会员
		addArticle: function(){
			$.post('/article/add',{title:vm.content.title,content:vm.content.content}, function(json) {
  			location.reload()
		  },'json');
		},
    //删除文章
		delArticle: function(id){
			$.post('/article/del',{id:id}, function(json) {
  			if(json==1){
          alert("删除成功")
          location.reload() 
        }else{
          alert("删除失败")
        }
		  },'json');
		},
    //修改文章资料
    setArticle: function(){
			$.post('/article/set',{title:vm.content.title,content:vm.content.content,id:vm.content.id}, function(json) {
  			location.reload()
		  },'json');
		}
	});
</script>
</body>
</html>
